use "C:\Real IMF GDPPC PPP"
merge iso3 year using "C:\Population.dta"
drop _merge
sort iso3 year
merge iso3 year using "C:\Area.dta"
drop _merge
keep if year>1989
sort iso3 year
gen lpop=log(pop)
sort country year
by country: ipolate lpop year, gen(plpop) epolate
gen ppop=exp(plpop)
gen pdens=ppop/area
drop if year==.
gen period=""
replace period="190-99" if year<2000
replace period="200-05" if year>1999 & year<2006
replace period="306-10" if year>2005 & year<2011
collapse (mean) rimfgpcppp pdens, by(country iso3 period)
gen rgdppc=rimfgpcppp
gen lrgdppc=log(rgdppc)
gen lr2=lrgdppc^2
gen lpdens=log(pdens)
sort iso3 period
save "C:\z1",replace

* iso3 year country imfgpcppp usdefl rimfgpcppp
use "C:\New Forest Database"
keep country iso3 year forsqkm
sort country year
bysort country: gen g1defor=((forsqkm/forsqkm[_n-1])^.1)-1
bysort country: gen g2defor=((forsqkm/forsqkm[_n-1])^.2)-1
bysort country: gen chkfor1=forsqkm[_n-1]*(1+g1defor)^10
bysort country: gen chkfor2=forsqkm[_n-1]*(1+g2defor)^5
gen xrate=g2defor
replace xrate=g1defor if year==2000
gen defrate=-1000*xrate
drop if year==1990
drop if year==.
gen period=""
replace period="190-99" if year==2000
replace period="200-05" if year==2005
replace period="306-10" if year==2010

* keep country iso3 defrate
sort iso3 period
save "C:\z2",replace

merge iso3 period using "C:\z1"
drop _merge
drop if lrgdppc==.
sort country period
save "C:\z3",replace
egen tc=tag(country)
keep if tc==1
gen cno=_n
keep country cno
sort country
save "C:\z4",replace
merge country using "C:\z3"
drop _merge
*replace year=2001 if year==2005
*replace year=2002 if year==2010
egen d99=pctile(defrate),p(99)
egen d95=pctile(defrate),p(95)
egen d90=pctile(defrate),p(90)
egen d85=pctile(defrate),p(85)
egen d80=pctile(defrate),p(80)
egen d75=pctile(defrate),p(75)
egen d1=pctile(defrate),p(1)
egen d5=pctile(defrate),p(5)
egen d10=pctile(defrate),p(10)
egen d15=pctile(defrate),p(15)
egen d20=pctile(defrate),p(20)
egen d25=pctile(defrate),p(25)
gen dd1=defrate>d1 & defrate<d99
gen dd5=defrate>d5 & defrate<d95
gen dd10=defrate>d10 & defrate<d90
gen dd15=defrate>d15 & defrate<d85
gen dd20=defrate>d20 & defrate<d80
gen dd25=defrate>d25 & defrate<d75

sort cno year
tsset cno year

*** Regressions Stored in file "C:\regres" for Table A1

xtreg defrate lrgdppc, re
outreg using "C:\regres",replace
estimates store random

predict pdefrate
gen cire=exp(-_b[_cons]/_b[lrgdppc])
drop pdefrate

xtreg defrate lrgdppc, fe
estimates store fixed 
outreg using "C:\regres",append

hausman fixed random

xtreg defrate lrgdppc if dd1==1, re
outreg using "C:\regres",append
estimates store random
predict pdefrate
gen cire1=exp(-_b[_cons]/_b[lrgdppc])
drop pdefrate

xtreg defrate lrgdppc if dd1==1, fe
estimates store fixed 
outreg using "C:\regres",append

hausman fixed random

xtreg defrate lrgdppc if dd5==1, re
outreg using "C:\regres",append
estimates store random
predict pdefrate
gen cire5=exp(-_b[_cons]/_b[lrgdppc])
drop pdefrate

xtreg defrate lrgdppc if dd5==1, fe
estimates store fixed 
outreg using "C:\regres",append

hausman fixed random


rreg defrate lrgdppc
outreg using "C:\regres",append
predict pdefrate
gen cirr=exp(-_b[_cons]/_b[lrgdppc])
drop pdefrate

rreg defrate lrgdppc if dd1==1
outreg using "C:\regres",append
predict pdefrate
gen cirr1=exp(-_b[_cons]/_b[lrgdppc])
drop pdefrate

rreg defrate lrgdppc if dd5==1
outreg using "C:\regres",append
predict pdefrate
gen cirr5=exp(-_b[_cons]/_b[lrgdppc])

gen crossinc=cirr5

gen zdefrate=defrate
replace zdefrate=1 if zdefrate<1
gen rav=pdefrate/zdefrate
gen mav=rav
replace mav=1 if rav<1
sort country
save "C:\Forest Multipliers",replace
keep if country=="Cambodia" | country=="China" | country=="Indonesia" | country=="Lao PDR" | country=="Malaysia" | country=="Myanmar" | country=="Thailand" | country=="Vietnam"
outsheet country year mav forsqkm defrate pdefrate rgdppc crossinc rav using "C:\SE Asia Forest Multipliers",replace
keep country year mav crossinc cire cire1 cire5 cirr cirr1 cirr5
replace country="Laos" if country=="Lao PDR"
sort country
save "C:\SE Asia Country Multipliers",replace
egen tcn=tag(country)
keep if tcn==1
keep if _n==1
outsheet cire cire1 cire5 cirr cirr1 cirr5 using "C:\Crossover Incomes",replace


